<?php

/**
 * 通知控制器
 *
 * 短信通知、微信通知等通知方式
 *
 * @package  app
 * @extends  Controller
 */
class Controller_Notice  extends Controller_Template {

    public $template = 'template';

    public function before(){
        parent::before();
        if(\tools\Tools::is_mobile()){
            \Response::redirect('/mgame/home');
        }
    }

    /**
     * 默认方法
     *
     * @access  public
     * @return  \Response
     */
    public function action_index()
    {
        $params = array(
            'title' => '首页',
            'menu' => 'home'
        );
        \View::set_global($params);
        $this->template->content = \View::forge('games/home');
    }

    /**
    * 发送手机验证码
    * @param $phone String 手机号码
    **/
    public function action_sms(){

        if(\Input::method() == 'POST'){
            $data = \Input::post();
            if( ! isset($data['phone']) || ! $data['phone']){
                die(json_encode(array('status' => 'err', 'msg' => '无效的参数', 'errcode' => 10)));
            }
            if(\Input::is_ajax()){
                die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0)));
            }
            die(json_encode(array('status' => 'err', 'msg' => '您获取的次数已达到上限，您不能使用该手机号码进行订餐。', 'errcode' => 10)));
        }
    }

    public function action_validate($type){
        if(\Input::method() == 'POST'){
            $data = \Input::post();
            if( ! isset($data['phone']) || ! $data['phone'] ||  ! isset($data['code']) || ! $data['code'] ){
                die(json_encode(array('status' => 'err', 'msg' => '无效的参数', 'errcode' => 10)));
            }

            /*$code = \Model_MoblieCode::query()->where('phone' => $data['phone'])->order_by('id', 'desc')->limit(1)->get_one();
            if($data['code'] == $code->code){
                if(\Input::is_ajax()){
                    die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0)));
                }
                die('验证成功');
            }*/

            die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0)));

            if(\Input::is_ajax()){
                die(json_encode(array('status' => 'err', 'msg' => '您已长时间未操作，已同服务器断开连接。<br/>请点击确定回到首页。', 'errcode' => 10)));
                die(json_encode(array('status' => 'err', 'msg' => '您已长时间未输入验证码，请点击重新获取。', 'errcode' => 10)));
                die(json_encode(array('status' => 'err', 'msg' => '您输入的验证码错误，请重新输入。如果已超时，请重新获取。', 'errcode' => 10)));
            }
            die('错误');
        }
    }
}